home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qdir.h.z / qdir.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  5.2 KB  |  201 lines

  1. /****************************************************************************
  2. ** $Id: qdir.h,v 2.9 1998/07/03 00:09:43 hanord Exp $
  3. **
  4. ** Definition of QDir class
  5. **
  6. ** Created : 950427
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QDIR_H
  25. #define QDIR_H
  26.  
  27. #ifndef QT_H
  28. #include "qstrlist.h"
  29. #include "qfileinfo.h"
  30. #endif // QT_H
  31.  
  32. typedef Q_DECLARE(QListM,QFileInfo)        QFileInfoList;
  33. typedef Q_DECLARE(QListIteratorM,QFileInfo) QFileInfoListIterator;
  34.  
  35.  
  36. class QDir
  37. {
  38. public:
  39.     enum FilterSpec { Dirs        = 0x001,
  40.               Files        = 0x002,
  41.               Drives        = 0x004,
  42.               NoSymLinks    = 0x008,
  43.               All        = 0x007,
  44.               TypeMask        = 0x00F,
  45.  
  46.               Readable        = 0x010,
  47.               Writable        = 0x020,
  48.               Executable    = 0x040,
  49.               RWEMask        = 0x070,
  50.               Modified        = 0x080,
  51.               Hidden        = 0x100,
  52.               System        = 0x200,
  53.               AccessMask    = 0x3F0,
  54.               DefaultFilter = -1 };
  55.  
  56.     enum SortSpec   { Name        = 0x00,
  57.               Time        = 0x01,
  58.               Size        = 0x02,
  59.               Unsorted        = 0x03,
  60.               SortByMask    = 0x03,
  61.               DirsFirst        = 0x04,
  62.               Reversed        = 0x08,
  63.               IgnoreCase    = 0x10,
  64.               DefaultSort   = -1 };
  65.  
  66.     QDir();
  67.     QDir( const char *path, const char *nameFilter = 0,
  68.       int sortSpec = Name | IgnoreCase, int filterSpec = All );
  69.     QDir( const QDir & );
  70.    ~QDir();
  71.     QDir       &operator=( const QDir & );
  72.     QDir       &operator=( const char *path );
  73.  
  74.     void    setPath( const char *path );
  75.     const char *path()        const;
  76.     QString    absPath()    const;
  77.     QString    canonicalPath()    const;
  78.  
  79.     QString    dirName() const;
  80.     QString    filePath( const char *fileName,
  81.               bool acceptAbsPath = TRUE ) const;
  82.     QString    absFilePath( const char *fileName,
  83.                  bool acceptAbsPath = TRUE ) const;
  84.  
  85.     static QString convertSeparators( const char *pathName );
  86.  
  87.     bool    cd( const char *dirName, bool acceptAbsPath = TRUE );
  88.     bool    cdUp();
  89.  
  90.     const char *nameFilter() const;
  91.     void    setNameFilter( const char *nameFilter );
  92.     FilterSpec filter() const;
  93.     void    setFilter( int filterSpec );
  94.     SortSpec sorting() const;
  95.     void    setSorting( int sortSpec );
  96.  
  97.     bool    matchAllDirs() const;
  98.     void    setMatchAllDirs( bool );
  99.  
  100.     uint    count() const;
  101.     const char *operator[]( int ) const;
  102.  
  103.     const QStrList *entryList( int filterSpec = DefaultFilter,
  104.                    int sortSpec   = DefaultSort  ) const;
  105.     const QStrList *entryList( const char *nameFilter,
  106.                    int filterSpec = DefaultFilter,
  107.                    int sortSpec   = DefaultSort   ) const;
  108.  
  109.     const QFileInfoList *entryInfoList( int filterSpec = DefaultFilter,
  110.                     int sortSpec   = DefaultSort  ) const;
  111.     const QFileInfoList *entryInfoList( const char *nameFilter,
  112.                     int filterSpec = DefaultFilter,
  113.                     int sortSpec   = DefaultSort   ) const;
  114.  
  115.     static const QFileInfoList *drives();
  116.  
  117.     bool    mkdir( const char *dirName,
  118.                   bool acceptAbsPath = TRUE ) const;
  119.     bool    rmdir( const char *dirName,
  120.                   bool acceptAbsPath = TRUE ) const;
  121.  
  122.     bool    isReadable() const;
  123.     bool    exists()   const;
  124.     bool    isRoot()   const;
  125.  
  126.     bool    isRelative() const;
  127.     void    convertToAbs();
  128.  
  129.     bool    operator==( const QDir & ) const;
  130.     bool    operator!=( const QDir & ) const;
  131.  
  132.     bool    remove( const char *fileName,
  133.                   bool acceptAbsPath = TRUE );
  134.     bool    rename( const char *name, const char *newName,
  135.                   bool acceptAbsPaths = TRUE  );
  136.     bool    exists( const char *name,
  137.                   bool acceptAbsPath = TRUE );
  138.  
  139.     static char separator();
  140.  
  141.     static bool setCurrent( const char *path );
  142.     static QDir current();
  143.     static QDir home();
  144.     static QDir root();
  145.     static QString currentDirPath();
  146.     static QString homeDirPath();
  147.     static QString rootDirPath();
  148.  
  149.     static bool match( const char *filter, const char *fileName );
  150.     static QString cleanDirPath( const char *dirPath );
  151.     static bool isRelativePath( const char *path );
  152.  
  153. private:
  154.     void    init();
  155.     bool    readDirEntries( const QString &nameFilter,
  156.                 int FilterSpec, int SortSpec  );
  157.  
  158.     QString    dPath;
  159.     QStrList   *fList;
  160.     QFileInfoList *fiList;
  161.     QString    nameFilt;
  162.     FilterSpec    filtS;
  163.     SortSpec    sortS;
  164.     uint    dirty    : 1;
  165.     uint    allDirs : 1;
  166. };
  167.  
  168.  
  169. inline const char *QDir::path() const
  170. {
  171.     return dPath.data();
  172. }
  173.  
  174. inline const char *QDir::nameFilter() const
  175. {
  176.     return (const char *) nameFilt;
  177. }
  178.  
  179. inline QDir::FilterSpec QDir::filter() const
  180. {
  181.     return filtS;
  182. }
  183.  
  184. inline QDir::SortSpec QDir::sorting() const
  185. {
  186.     return sortS;
  187. }
  188.  
  189. inline bool QDir::matchAllDirs() const
  190. {
  191.     return allDirs;
  192. }
  193.  
  194. inline bool QDir::operator!=( const QDir &d ) const
  195. {
  196.     return !(*this == d);
  197. }
  198.  
  199.  
  200. #endif // QDIR_H
  201.